<template>
  <div>
    <el-form :model="formDate" :rules="rules">
      <el-form-item label="手机号码" prop="mobile">
        <el-input v-model="formDate.mobile" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="formDate.password" />
      </el-form-item>
      <el-form-item label="确认密码" prop="passwords">
        <el-input v-model="formDate.passwords" />
      </el-form-item>
      <el-form-item>
        <el-button>提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    const validatePass = (rule, value, callback) => {
      if (value === this.formDate.password) {
        callback()
      } else {
        callback(new Error('请输入一致的密码'))
      }
    }
    return {
      formDate: {
        mobile: '',
        password: '',
        passwords: ''
      },
      rules: {
        mobile: [
          { required: true, message: '请输入手机号码', trigger: 'blur' },
          { pattern: /^1[3-9][0-9]{9}$/, message: '请输入正常的手机号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入手机号码', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        passwords: [
          { required: true, message: '请输入手机号码', trigger: 'blur' },
          { validator: validatePass, trigger: 'blur' }]
      }
    }
  }

}
</script>

<style>

</style>
